{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append(\"..\") # Adds higher directory to python modules path.\n",
    "import dp\n",
    "import gym\n",
    "import gym_gridworld"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "env = gym.make('square-gridworld-v0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Generate random policy with 4x4 GridWorld\n",
    "policy = dp.generate_random_policy(env)\n",
    "V, policy = dp.policy_iteration(policy, env)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0., -1., -2., -3., -1., -2., -3., -2., -2., -3., -2., -1., -3.,\n",
       "       -2., -1.,  0.])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "V"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "State:1 Action: LEFT\n",
      "State:2 Action: LEFT\n",
      "State:3 Action: DOWN\n",
      "State:4 Action: UP\n",
      "State:5 Action: UP\n",
      "State:6 Action: UP\n",
      "State:7 Action: DOWN\n",
      "State:8 Action: UP\n",
      "State:9 Action: UP\n",
      "State:10 Action: RIGHT\n",
      "State:11 Action: DOWN\n",
      "State:12 Action: UP\n",
      "State:13 Action: RIGHT\n",
      "State:14 Action: RIGHT\n"
     ]
    }
   ],
   "source": [
    "dp.print_policy(policy)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
